<?php
    $item_menu[0] = 5;
    $item_menu[1] = 2 ;
    $title = 'Productos';    

	if (!defined('URL')) { include('header.php'); }
    
	if (!isset($_SESSION["admin"])) {redirect("login.php");	exit(); }

	if(!empty($_SESSION['Msg'])) { echo mensaje_ok($_SESSION['Msg']);$_SESSION['Msg']='';	}
    
    
	$id     		= request('id',0);
    $familia_id     = request('familia_id',0);
	$accion 		= request('accion','listar');



	switch ($accion) {
		case 'eliminar': /******************************************************************************** DELETE *********************/
			// Elimina la publicacion
			$cond 	= "delete from productos where id='$id'";
			$ok		= $db->Execute($cond);
			if ($ok) { $_SESSION['Msg'] = 'El Producto se elimin&oacute; correctamente.';
			} else { $_SESSION['Msg'] = $cond."<hr>".'ERROR!! No se pudo eliminar el producto.';	}
			redirect("productos.php?accion=listar&familia_id=$familia_id");
			die();

			break;

	}

	if ($accion=='listar') { /******************************************************************************** LISTAR*********************/

		//----------------------------------------------------------------
		//                                              Obtiene los planes
		//----------------------------------------------------------------
		$sql = "select * from planes_alojamientos where activo='1' order by plan ASC";
		$rs  = $db->CacheExecute($sql);
		$Planes = $rs->GetRows();	

		//----------------------------------------------------------------
		//                                           Obtiene las Familias
		//----------------------------------------------------------------
		$Familias = crearArbol(0);
		$parent_id = 0;
		$fam_url='';
		$mostrar_familia = '<select name="mostrar_familia" onChange="document.location.href=\'productos.php?accion=listar&familia_id=\'+this.value">';
		foreach($Familias as $dd){
				if ($familia_id == 0) { $familia_id = $dd['id']; }
				if ($familia_id == $dd['id']) { 
					$fam_url = $dd['urlamigable1'];
					$sel = "selected='selected'"; 
				} else {$sel='';}
				
				$separador = "";
				if ($dd['nivel'] == 2 ) {
					$separador = "------";
				} elseif ($dd['nivel'] == 3 ) {
					$separador = "------------";
				} elseif ($dd['nivel'] == 4 ) {
					$separador = "------------------";
				}
				$mostrar_familia.= "<option value='{$dd['id']}' $sel >$separador {$dd['nombre1']}</option>";
		}
		$mostrar_familia.= "</select>";

		$cond 		= "select * from productos where familia_id = '$familia_id'  order by activo DESC, titulo ASC";
		$rs 		= $db->Execute($cond);
		$Productos 	= $rs->GetRows();

		
		include_once('productos_listar.html.php');
        
	}

?>
		</td>
        </tr>
      </table></td>
    </tr>
</tbody></table>

</body></html>